//
//  MHShareAppViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/6/6.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHShareAppViewModel.h"
#import "MHCommonGroupViewModel.h"
#import "MHCommonArrowItemViewModel.h"
#import "MHDownLoadH5.h"

@implementation MHShareAppViewModel

- (void)initialize{
    [super initialize];
    self.title = @"推荐给朋友";
        @weakify(self);
    MHCommonGroupViewModel *group0 = [MHCommonGroupViewModel groupViewModel];
    MHCommonArrowItemViewModel *wechat = [MHCommonArrowItemViewModel itemViewModelWithTitle:@"推荐给微信好友" icon:@"icon_share_wechat"];
    wechat.operation = ^{
        @strongify(self);
        [[self.fetchQrCodeLinkCommond execute:nil] subscribeNext:^(MHDownLoadH5 *dowload) {
            OSMessage *msg=[[OSMessage alloc] init];
            msg.title=dowload.title;
            msg.link = dowload.downUrl;
            msg.desc = dowload.intro;
            UIImage *thumbImage = [UIImage imageNamed:@"AppIcon"];
            NSData *compressData = [thumbImage compressWithLengthLimit:31 *1024];
            msg.image = compressData;
            [OpenShare shareToWeixinSession:msg Success:^(OSMessage *message) {
                
            } Fail:^(OSMessage *message, NSError *error) {
            }];
        }];
    };
    
    MHCommonArrowItemViewModel *shareToTimeLine = [MHCommonArrowItemViewModel itemViewModelWithTitle:@"推荐给微信朋友圈" icon:@"icon_share_timeline"];
    shareToTimeLine.operation = ^{
        @strongify(self);
        [[self.fetchQrCodeLinkCommond execute:nil] subscribeNext:^(MHDownLoadH5 *dowload) {
            OSMessage *msg=[[OSMessage alloc] init];
            msg.title=[NSString stringWithFormat:@"《%@》%@",dowload.title,dowload.intro];
            msg.link = dowload.downUrl;
            msg.desc = dowload.intro;
            UIImage *thumbImage = [UIImage imageNamed:@"AppIcon"];
            NSData *compressData = [thumbImage compressWithLengthLimit:31 *1024];
            msg.image = compressData;
            [OpenShare shareToWeixinTimeline:msg Success:^(OSMessage *message) {
                
            } Fail:^(OSMessage *message, NSError *error) {
            }];
        }];
    };
    //MHCommonArrowItemViewModel *link = [MHCommonArrowItemViewModel itemViewModelWithTitle:@"推荐给微信朋友圈" icon:@"icon_share_link"];
    MHCommonArrowItemViewModel *circleQrCode = [MHCommonArrowItemViewModel itemViewModelWithTitle:@"百唠二维码" icon:@"icon_share_qrcode"];
    
//    circleQrCode.model = self.circleInfo;
    group0.itemViewModels = @[ wechat,shareToTimeLine,circleQrCode];
    self.dataSource = @[group0];
    

    self.fetchQrCodeLinkCommond = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        return [[self.services.client fetchDownloadAppH5] mh_parsedResults];
    }];
    
}


@end
